package lock_250417;

import java.util.concurrent.TimeUnit;

public class notify2 {
    private static final Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            synchronized (lock) {
                System.out.println("线程1进入等待");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程1恢复执行");
            }
        }).start();

        TimeUnit.SECONDS.sleep(1);
        synchronized (lock) {
            System.out.println("主线程获取锁并notify");
//            lock.notify();  // 将线程1从Wait Set移到Entry Set

            // 此时线程1处于BLOCKED状态，等待锁释放
            System.out.println("主线程仍持有锁");
            Thread.sleep(1000);  // 模拟工作
        } // 这里释放锁后，线程1才能获取锁继续执行
    }
}
